﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using EZCRS.HCMS.Bll.AIR;
using EZCRS.HCMS.Bll;
using EZCRS.HCMS.Entity;
using System.Collections.Generic;
using System.Text;
using EZCRS.HCMS.Web;

namespace EZCRS.HCMS.Web.manage.booklog
{
    public partial class bookingdetail1 : ManageBase
    {
        public string RoomCode, RateCode, StartDate, EndDate,Iata,verifyCode="",checkIn,checkOut;
        int pid=0,roomTotal=0;

        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(EZCRS.HCMS.myajax.BookLog));

            if (!Page.IsPostBack)
            {
                int id = CFun.RequestNumber("id");
                if (id > 0)
                {
                    
                    DataRow dr = new BllBookLogView().GetBookLog(id);
                    if (dr != null)
                    {
                        ddlstatus.DataSource = DataAcl.Common.BookingStatus();
                        ddlstatus.DataTextField = "Value";
                        ddlstatus.DataValueField = "Key";
                        ddlstatus.DataBind();
                        ddlstatus.SelectedValue = "0";

                        LabConfirm.Text = dr["updatetime"].ToString();
                        LabRooms.Text = DataAcl.Common.BookStatusTxt(dr["status"].ToString());
                        Label34.Text = DataAcl.Common.getBookingStates(Convert.ToInt32(dr["getstatus"].ToString()));
                        LabTrueName.Text = dr["confnum"].ToString();
                        Label33.Text = dr["iata"].ToString();
                        LabCheck.Text = dr["guestlastname"].ToString() + " " + dr["guestfirstname"].ToString();
                        Label32.Text = "";//身份证
                        LabCreateDate.Text = "";//其他客人
                        LabAddress.Text = dr["rooms"].ToString();
                        Label31.Text = dr["adults"].ToString();
                        LabTelphone.Text = dr["indate"].ToString();
                        LabTelphone0.Text = dr["outdate"].ToString();
                        Label29.Text = dr["roomtype"].ToString();
                        LabHotel.Text = dr["totalmount"].ToString().Replace(".0000","");
                        Label28.Text = dr["guadesc"].ToString();
                        LabRoomName.Text = dr["dailyprice"].ToString();
                        LabCXL.Text = dr["remarks"].ToString();
                        LabGUA.Text = "";//房型描述
                        Label5.Text = dr["rateclass"].ToString();
                        Label7.Text = dr["cxldesc"].ToString();
                        Label9.Text = dr["guadesc"].ToString();
                        Label11.Text = dr["cctype"].ToString();
                        Label27.Text = "*********************";
                        Label13.Text = dr["ccname"].ToString();
                        Label26.Text = dr["ccexp"].ToString();
                        Label15.Text = "";//暂无
                        Label17.Text = "";//其他客人姓名
                        Label19.Text = "";//客人特殊要求
                        Label21.Text = "";//dr[""].ToString();//担保状态
                        Label25.Text = dr["pay"].ToString();
                        Label23.Text = "";//担保类型
                        txtContactName2.Text = dr["confnum"].ToString();
                        ddlstatus.SelectedValue = dr["getstatus"].ToString();
                        pid = Convert.ToInt32(dr["property_id"].ToString());
                        Iata = dr["iata"].ToString();
                        verifyCode = dr["verifycode"].ToString();
                        roomTotal = Convert.ToInt32(dr["rooms"].ToString());
                        checkIn = Convert.ToDateTime(dr["indate"].ToString()).ToShortDateString();
                        checkOut = Convert.ToDateTime(dr["outdate"].ToString()).ToShortDateString();
                    }
                }

                //查询酒店信息
                if (pid > 0)
                {
                    HCRS_Hotel hotel = new SqlClient.sql_hcrs_hotel().GetHotelByPID(pid);
                    if (hotel != null)
                    {
                        //初始化酒店信息
                        labHotelTitle.Text = hotel.Title;
                        labHotelPid.Text = hotel.pid.ToString();
                        labHotelGroup.Text = hotel.GroupID.ToString();
                        labHotelType.Text = "";
                        labHotelAir.Text = "";
                        latHotelType1.Text = "";
                        labHotelPms.Text = "";
                        labHotelAddress.Text = hotel.address;
                        labHotelDist.Text = hotel.Districtid.ToString();
                        labHotelComm.Text = hotel.Commercialid.ToString();
                        labHotelTel.Text = hotel.Phone;
                        labHotelFax.Text = hotel.Fax;
                        labHotelEmail.Text = "";
                    }
                }

                #region
                if (Iata.Length > 0)
                {
                    List<HCRS_Corp> corpList = new BllHCRS_Corp().GetItem("iata='" + Iata + "'");
                    if (corpList.Count > 0)
                    {
                        HCRS_Corp corp = corpList[0];

                        //初始化渠道信息
                        
                        labTaCompanyName.Text = corp.Corp_name;
                        labTaTel.Text = corp.tel;
                        labTaFax.Text = corp.fax;
                        labTaEmail.Text = corp.email;
                        labTaIata.Text = corp.IATA;

                        HCRS_CorpUser corpuser = new BllHCRS_CorpUser().GetItem(" parentid="+corp.Corp_id.ToString()+" ")[0];
                        labTaName.Text = corpuser.UserName;
                    }

                }
                #endregion

                if (verifyCode != "")
                {
                    //备注信息
                    List<Hcrs_CCComment> commentList = new BllHcrs_CCComment().GetItem(" verifycode='"+verifyCode+"' ", " id desc ");
                    if (commentList.Count > 0)
                    {
                        Hcrs_CCComment comment = commentList[0];
                        //初始化第一个备注
                        labcomuser.Text = comment.inname;
                        labcomdate.Text = comment.indate.ToString();
                        txtcomdetail.Text = comment.indetail;
                    }
                }

                StringBuilder strB = new StringBuilder();
                strB.Append("<table id=\"roomdaylist\" width=\"100%\">");
                List<Hcrs_CCDayRoom> dayRoomList = new BllHcrs_CCDayRoom().GetItem(" verifycode='"+verifyCode+"' ");
                if (dayRoomList.Count > 0)
                {
                    foreach (Hcrs_CCDayRoom dayRoom in dayRoomList)
                    {
                        strB.Append("<tr><td>客人姓名：<input type=text size=\"10\" name=\"roomdayname\" value=\"" + dayRoom.names + "\" class=\"text-line w100\">状态：<select name=\"roomdaystatus\">");

                        if (dayRoom.status == "")
                        {
                            strB.Append("<option value=\"\" selected>无</option>");
                        }
                        else
                        {
                            strB.Append("<option value=\"\">无</option>");
                        }
                        if (dayRoom.status == "1")
                        {
                            strB.Append("<option value=\"1\" selected>入住</option>");
                        }
                        else
                        {
                            strB.Append("<option value=\"1\">入住</option>");
                        }

                        if (dayRoom.status == "2")
                        {
                            strB.Append("<option value=\"2\" selected>离店</option>");
                        }
                        else
                        {
                            strB.Append("<option value=\"2\">离店</option>");
                        }
                        if (dayRoom.status == "3")
                        {
                            strB.Append("<option value=\"3\" selected>应到未到</option>");
                        }
                        else
                        {
                            strB.Append("<option value=\"3\">应到未到</option>");
                        }

                        strB.Append("</select>房号：<input type=text size=\"10\" name=\"roomdayroomno\" value=\"" + dayRoom.roomno + "\" class=\"text-line w100\">入住：<input type=text size=\"10\" name=\"roomdaycheckin\" value=\"" + dayRoom.checkin.Value.ToShortDateString() + "\" class=\"text-line w100\">离店：<input type=text size=\"10\" name=\"roomdaycheckout\" value=\"" + dayRoom.checkout.Value.ToShortDateString() + "\"><input type=\"hidden\" name=\"hidrid\" value=\"" + dayRoom.Id.ToString() + "\" class=\"text-line w100\"></td></tr>");
                    }
                }
                else 
                {
                    for (int i = 0; i < roomTotal; i++)
                    {
                        strB.Append("<tr><td>客人姓名：<input type=text size=\"10\" name=\"roomdayname\" class=\"text-line w100\">状态：<select name=\"roomdaystatus\"><option value=\"\">无</option><option value=\"1\">入住</option><option value=\"2\">离店</option><option value=\"3\">应到未到</option></select>房号：<input type=text size=\"10\" name=\"roomdayroomno\" class=\"text-line w100\">入住：<input type=text size=\"10\" name=\"roomdaycheckin\" value=\"" + checkIn + "\" class=\"text-line w100\">离店：<input type=text size=\"10\" name=\"roomdaycheckout\" value=\"" + checkOut + "\" class=\"text-line w100\"><input type=\"hidden\" name=\"hidrid\" value=\"0\" ></td></tr>");
                    }
                }
                strB.Append("</table>");
                ltlroomday.Text = strB.ToString();
            }
        }

       
            
        
    }
}
